home *** CD-ROM | disk | FTP | other *** search
/ The Web Design Wow! Book Companion / Web Design Wow!.iso / mac / Windows / HTML Editors / HoTMetaL Pro 4 / Setup / CGI.Z / countdwn.pl < prev    next >
Encoding:
Perl Script  |  1996-04-17  |  5.0 KB  |  224 lines

  1. #!/usr/bin/perl
  2.  
  3. # Countdown Script for the WWW
  4. # Version 1.21
  5. # Created by Matt Wright
  6. # Created on: 8/31/95   Last Modified: 10/8/95
  7. # I can be contacted at:        mattw@misha.net
  8. # Scripts can be found at:      http://www.worldwidemart.com/scripts/
  9.  
  10. ##################################
  11. # Define Variables
  12.  
  13. # @from_date = (yyyy,mm,dd,hh,mm,ss);
  14. # Which means: (year,month,day,hour,minute,second)
  15. @from_date = (2000,1,1,0,0,0);
  16.  
  17. # Done
  18. ##################################
  19.  
  20.  
  21. $ENV{'QUERY_STRING'} =~ s/%2C/,/g;
  22. $ENV{'QUERY_STRING'} =~ s/=//g;
  23.  
  24. if ($ENV{'QUERY_STRING'}) {
  25.    @from_date = split(/,/, $ENV{'QUERY_STRING'});
  26. }
  27.  
  28. # Define when various things occur, different dates, etc...
  29. &define_dates;
  30.  
  31. # Calculate the Differences in the two dates
  32. &calc_dates;
  33.  
  34. # Make Sure we don't get negative times.. That's not cool...
  35. &no_negative;
  36.  
  37. # Top of HTML Page Information
  38. &html_header;
  39.  
  40. # We don't want it to say 1 Years, now, do we?  Of course not!
  41. &proper_english;
  42.  
  43. # End of HTML Page Information
  44. &html_trailer;
  45.  
  46. #####################################
  47. # Subroutines
  48.  
  49. sub define_dates {
  50.    ($f_year,$f_month,$f_day,$f_hour,$f_minute,$f_second) = @from_date;
  51.  
  52.    ($second,$minute,$hour,$day,$month,$year,$wday,$yday,$isdst) = localtime(time);
  53.  
  54.    $year ="19$year";
  55.  
  56.    &leap_year_check;
  57.  
  58.    @months = ("XX","January","February","March","April","May","June","July",
  59.               "August","September","October","November","December");
  60.  
  61.    @days = ("XX","1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th",
  62.             "11th","12th","13th","14th","15th","16th","17th","18th","19th",
  63.             "20th","21st","22nd","23rd","24th","25th","26th","27th","28th",
  64.             "29th","30th","31st");
  65.  
  66.    @days_in_month = (31,$feb_days,31,30,31,30,31,31,30,31,30,31);
  67.  
  68.    $date_term = "$months[$f_month] $days[$f_day]";
  69.  
  70.    unless ($f_year eq 'XX') {
  71.       $date_term = "$date_term, $f_year";
  72.    }
  73.    unless ($f_hour eq 'XX') {
  74.       $date_term = "$date_term $f_hour";
  75.    }
  76.    unless ($f_minute eq 'XX') {
  77.       if ($f_minute < 10) {
  78.          $date_term = "$date_term:0$f_minute";
  79.       }
  80.       else {
  81.          $date_term = "$date_term:$f_minute";
  82.       }
  83.    }
  84.    unless ($f_second eq 'XX') {
  85.       if ($f_second < 10) {
  86.          $date_term = "$date_term:0$f_second";
  87.       }
  88.       else {
  89.          $date_term = "$date_term:$f_second";
  90.       }
  91.    }
  92.  
  93.    $current_date = "$months[($month + 1)] $days[$day], $year $hour";
  94.    if ($minute < 10) {
  95.       $current_date = "$current_date:0$minute";
  96.    }
  97.    else {
  98.       $current_date = "$current_date:$minute";
  99.    }
  100.    if ($second < 10) {
  101.       $current_date = "$current_date:0$second";
  102.    }
  103.    else {
  104.       $current_date = "$current_date:$second";
  105.    }
  106.  
  107. }
  108.  
  109. sub leap_year_check {
  110.    $yeardiv = ($year / 4);
  111.    $yearint = int($yeardiv);
  112.    $yeardiv1 = ($year / 100);
  113.    $yearint1 = int($yeardiv1);
  114.  
  115.    if ($yeardiv eq $yearint && $yeardiv1 ne $yearint1) {
  116.       $feb_days = "28";
  117.    }
  118.    else {
  119.       $feb_days = "29";
  120.    }
  121. }
  122.  
  123. sub calc_dates {
  124.    $real_year = ($f_year - $year);
  125.    $real_month = (($f_month - 1) - $month);
  126.    $real_day = ($f_day - $day);
  127.    $real_hour = ($f_hour - $hour);
  128.    $real_minute = ($f_minute - $minute);
  129.    $real_second = ($f_second - $second);
  130. }
  131.  
  132. sub no_negative {
  133.    if ($real_second < 0) {
  134.       $real_second = ($real_second + 60);
  135.       $real_minute--;
  136.    }
  137.  
  138.    if ($real_minute < 0) {
  139.       $real_minute = ($real_minute + 60);
  140.       $real_hour--;
  141.    }
  142.  
  143.    if ($real_hour < 0) {
  144.       $real_hour = ($real_hour + 24);
  145.       $real_day--;
  146.    }
  147.  
  148.    if ($real_day < 0) {
  149.      $real_day = ($real_day + @days_in_month[$month]);
  150.       $real_month--;
  151.    }
  152.  
  153.    if ($real_month < 0) {
  154.       $real_month = ($real_month + 12);
  155.       $real_year--;
  156.    }
  157. }
  158.  
  159. sub proper_english {
  160.    unless ($f_year eq 'XX') {
  161.       if ($real_year eq '1') {
  162.          print "$real_year Year<br>\n";
  163.       } else {
  164.          print "$real_year Years<br>\n";
  165.       }
  166.    }
  167.  
  168.    unless ($f_month eq 'XX') {
  169.       if ($real_month eq '1') {
  170.          print "$real_month Month<br>\n";
  171.       } else {
  172.          print "$real_month Months<br>\n";
  173.       }
  174.    }
  175.  
  176.    unless ($f_day eq 'XX') {
  177.       if ($real_day eq '1') {
  178.          print "$real_day Day<br>\n";
  179.       } else {
  180.          print "$real_day Days<br>\n";
  181.       }
  182.    }
  183.  
  184.    unless ($f_hour eq 'XX') {
  185.       if ($real_hour eq '1') {
  186.          print "$real_hour Hour<br>\n";
  187.       } else {
  188.          print "$real_hour Hours<br>\n";
  189.       }
  190.    }
  191.  
  192.    unless ($f_minute eq 'XX') {
  193.       if ($real_minute eq '1') {
  194.          print "$real_minute Minute<br>\n";
  195.       } else {
  196.          print "$real_minute Minutes<br>\n";
  197.       }
  198.    }
  199.  
  200.    unless ($f_second eq 'XX') {
  201.       if ($real_second eq '1') {
  202.          print "$real_second Second<br>\n";
  203.       } else {
  204.          print "$real_second Seconds<br>\n";
  205.       }
  206.    }
  207.  
  208.  
  209. }
  210.  
  211. sub html_header {
  212.    print "Content-type: text/html\n\n";
  213.    print "<html><head><title>Countdown to: $date_term</title></head>\n";
  214.    print "<body><center><h1>Countdown to: $date_term</h1>\n";
  215.    print "<hr>\n";
  216. }
  217.  
  218. sub html_trailer {
  219.    print "<hr>\n";
  220.    print "It is currently $current_date\n";
  221.    print "</center>\n";
  222.    print "</body></html>\n";
  223. }
  224.